home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / Progress CDEF 1.0.2 / Progress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-20  |  3.2 KB  |  156 lines  |  [TEXT/KAHL]

  1. /* ----------------------------------------------------------------------
  2.  
  3.     Progress CDEF
  4.     version 1.0.2
  5.     20 March 1994
  6.     
  7.     Written by: Paul Celestin
  8.     
  9.     This CDEF displays a progress thermometer.
  10.     
  11.     940320 - 1.0.2 - more bug fixes
  12.     
  13.     931012 - 1.0.1 - bug fixes
  14.     
  15.     930927 - 1.0.0 - initial release
  16.  
  17. ---------------------------------------------------------------------- */
  18.  
  19. # include    <Controls.h>
  20. # include    <QuickDraw.h>
  21.  
  22. /* ----------------------------------------------------------------------
  23. prototypes
  24. ---------------------------------------------------------------------- */
  25. pascal     long        main(short, ControlHandle, short, long);
  26.          void         drawIt(ControlHandle, short);
  27.  
  28. /* ----------------------------------------------------------------------
  29. main - here is where it all began...
  30. ---------------------------------------------------------------------- */
  31. pascal long main
  32.     (
  33.     short            variation,
  34.     ControlHandle    theControl,
  35.     short            message,
  36.     long            param
  37.     )
  38.  
  39. {
  40.     long            returnValue = 0L;
  41.     char            state = HGetState((Handle)theControl);
  42.  
  43.     switch(message)
  44.     {
  45.         case drawCntl:
  46.             drawIt(theControl,variation);
  47.         case testCntl:
  48.             break;
  49.         case calcCRgns:
  50.             break;
  51.           case initCntl:
  52.               break;
  53.         case dispCntl:
  54.             break;
  55.         case posCntl:
  56.             break;
  57.         case thumbCntl:
  58.             break;
  59.         case dragCntl:
  60.             break;
  61.         case autoTrack:
  62.             break;
  63.         case calcCntlRgn:
  64.             break;
  65.         case calcThumbRgn:
  66.             break;
  67.         default:
  68.             break;
  69.     }
  70.  
  71.     HSetState((Handle)theControl,state);
  72.  
  73.     return(returnValue);                /* tell them what happened */
  74. }
  75.  
  76. /* ----------------------------------------------------------------------
  77. drawIt - here is where we actually draw the control
  78. ---------------------------------------------------------------------- */
  79. static void drawIt
  80.     (
  81.     ControlHandle    control,
  82.     short            variation
  83.     )
  84.  
  85. {
  86.     Rect             myRect;
  87.     PenState        oldPenState;
  88.     int                myValue = GetCtlValue(control),
  89.                     myMax = GetCtlMax(control),
  90.                     myMin = GetCtlMin(control),
  91.                     myColor,
  92.                     width = 0,
  93.                     range = 100;
  94.  
  95.     if (!(*control)->contrlVis)                /* if not visible, do nothing */
  96.         return;
  97.  
  98.     GetPenState(&oldPenState);                /* save off current environment */
  99.  
  100.     myRect = (*control)->contrlRect;        /* define our control rect */
  101.     
  102.     PenNormal();                            /* make pen normal */
  103.     
  104.     FrameRect(&myRect);                        /* draw border around the control */
  105.     InsetRect(&myRect,1,1);
  106.  
  107.     ForeColor(whiteColor);
  108.     BackColor(whiteColor);
  109.     PaintRect(&myRect);
  110.  
  111.     width = myRect.right - myRect.left;        /* width in pixels of the control */
  112.     range = myMax - myMin;
  113.     
  114.     if (range < 10) range = 10;                /* to deal with screwy ranges */
  115.     
  116.     myRect.right = myRect.left + (myValue * width) / range;
  117.     
  118.     switch (GetCRefCon(control))
  119.     {
  120.         case 1:
  121.             myColor = redColor;
  122.             break;
  123.         case 2:
  124.             myColor = greenColor;
  125.             break;
  126.         case 3:
  127.             myColor = blueColor;
  128.             break;
  129.         case 4:
  130.             myColor = cyanColor;
  131.             break;
  132.         case 5:
  133.             myColor = magentaColor;
  134.             break;
  135.         case 6:
  136.             myColor = yellowColor;
  137.             break;
  138.         case 7:
  139.             myColor = whiteColor;
  140.             break;
  141.         default:
  142.             myColor = blackColor;
  143.             break;
  144.     }
  145.     
  146.     ForeColor(myColor);
  147.     BackColor(myColor);
  148.     PaintRect(&myRect);
  149.  
  150.     ForeColor(blackColor);
  151.     BackColor(whiteColor);
  152.     SetPenState(&oldPenState);                /* restore the original environment */
  153.     
  154.     return;                                    /* we are done drawing */
  155. }
  156.